package com.tensquare.qa.controller;

import com.tensquare.qa.client.LabelClient;
import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.ProblemService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;
    @Autowired
    private LabelClient labelClient;

    //1.查询最新问题列表
    @GetMapping("newlist/{labelid}/{page}/{size}")
    public Result newList(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        //1.调用服务查询最新问题列表
        PageResult<Problem> pageResult=problemService.findNewList(labelid,page,size);
        //2.返回结果
        return new Result(true,StatusCode.OK,"查询最新问题列表成功！",pageResult);
    }
    //2.查询热门问题
    @GetMapping("hotlist/{labelid}/{page}/{size}")
    public Result hotList(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        //2.1调用服务查询热门问题列表
        PageResult<Problem> pageResult=problemService.findHotList(labelid,page,size);
        //2.2返回结果x
        return new Result(true,StatusCode.OK,"查询热门问题列表成功！",pageResult);
    }

    //3.根据标签id查询得到标签对象(调用其他微服务)
    @GetMapping("label/{labelId}")
    public Result findById(@PathVariable String labelId){
        return labelClient.findById(labelId);
    }
}
